define (require, exports, module) ->
  require 'mods/info_order/info_order_css.css'

  infoOrderApi = require 'mods/info_order/info_order_api'

  module.exports = Vue.extend

    # 组件模板
    template: require 'mods/info_order/info_order_tpl.js'

    # 定义变量
    data: () ->
      # 是否加载完成
      loadedSucc: false
      # 加载失败提示语
      loadedFail: ''
      # 点击查看更多
      viewMoreTxt: '查看更多'
      # 用户信息
      userInfo: {}
      # 当前页码
      page: 1
      # 列表是否为空
      listIsEmpty: true

      # 我的产品列表
      orderList: []

    # 定义方法
    methods:

      # 插件加载
      pluginLoad: () ->
        self = @

      # 加载成功
      loadedSuccFunc: () ->
        self = @
        self.$nextTick () ->
          # 加载成功标识
          self.loadedSucc = true
          # 插件加载
          self.pluginLoad()

      gotoPage: (page) ->
        self = @
        self.page = parseInt page
        self.queryInfoOrder()

      # 从session中获取用户信息
      getUserSession: () ->
        self = @
        oStr = sessionStorage.getItem 'userInfo'
        self.userInfo = JSON.parse oStr

        # 若未绑定客户号，则显示暂无订单
        if '未绑定' is self.userInfo?.client_id
          self.listIsEmpty = true
          # 加载成功 - 处理函数
          self.loadedSuccFunc()

        # 否则，分页查询订单列表
        else
          self.gotoPage self.page

      # 查询订单列表
      queryInfoOrder: () ->
        self = @

        params =
          "client_id": self.userInfo?.client_id
          "id_kind": self.userInfo?.id_kind
          "id_no": self.userInfo?.id_no
          "prodta_no": "87"
          "trans_account": ""
          "allot_no": ""
          "business_flag": 0
          "begin_date": 0
          "end_date": 0
          "dsorgan_flag": "0"
          "agency_no": "GF9"
          "currentpage": self.page
          "pagesize": 10

        return infoOrderApi.queryInfoOrder params
          .then (res) ->
            tmpArr = res?.data?.table_data

            # 如果订单列表数据为空
            if 0 is self.orderList.length
              if 0 is tmpArr?.length
                self.listIsEmpty = true
              else
                self.orderList = tmpArr
                self.listIsEmpty = false

            # 如果订单列表数据不为空
            else
              self.listIsEmpty = false
              if 0 is tmpArr?.length
                self.viewMoreTxt = '已显示全部内容'
              else
                for item in tmpArr
                  self.orderList.push item

            # 加载成功 - 处理函数
            self.loadedSuccFunc()

          .catch (err) ->
            console.error '查询订单列表出错:',err

    # 引用组件
    components:
      'c-info-side': require 'mods/info_side/info_side_mod'

    # 计算属性
    computed:

      # 加载中的样式
      loaddingClass: () ->
        self = @
        if self.loadedSucc
          return 'c-hidden'
        if self.loadedFail
          return 'c-hidden'
        return ''

      # 加载成功的样式
      loadedSuccClass: () ->
        self = @
        return if self.loadedSucc then '' else 'c-vhidden'

      # 加载失败的样式
      loadedFailClass: () ->
        self = @
        return if self.loadedFail then '' else 'c-hidden'

    # 组件初始化执行
    mounted: () ->
      self = @
      # 从session中获取用户信息
      self.getUserSession()